package com.flyduck.mall.pms.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyduck.mall.pms.admin.service.AdminAdService;
import com.flyduck.mall.pms.admin.vo.*;
import com.flyduck.ss.common.core.domain.R;
import com.flyduck.mall.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @program: vueshop
 * @description:
 * @author: flyduck
 * @create: 2024-06-03 21:39
 **/
@RestController
@RequestMapping("/admin/ad")
public class AdminAdController extends BaseController {

    @Resource
    private AdminAdService adminAdService;

    @GetMapping("/getAdPage")
    public R<Page<AdminAdRespVO>> getAdPage(AdminAdQueryReqVO adminAdQueryReqVO){
        Page<AdminAdRespVO> adminAdRespVOPage = adminAdService.getAdPage(getPage(),adminAdQueryReqVO);
        return R.ok(adminAdRespVOPage);
    }

    @GetMapping("/getAdDetailsById/{id}")
    public R<AdminAdDetailsRespVO> getAdDetailsById(@PathVariable("id") Long id){
        AdminAdDetailsRespVO adminAdDetailsRespVO = adminAdService.getAdDetailsById(id);
        return R.ok(adminAdDetailsRespVO);
    }

    @PostMapping("/saveAd")
    public R<Void> saveAd(@Validated @RequestBody AdminAdSaveReqVO adminAdSaveReqVO){
        adminAdService.saveAd(adminAdSaveReqVO);
        return R.ok();
    }

    @PostMapping("/updateAd")
    public R<Void> updateAd(@Validated @RequestBody AdminAdUpdateReqVO adminAdUpdateReqVO){
        adminAdService.updateAd(adminAdUpdateReqVO);
        return R.ok();
    }

    @PostMapping("/batchDeleteByIds")
    public R<Void> batchDeleteByIds(@RequestBody Long[] ids){
        adminAdService.batchDeleteByIds(Arrays.asList(ids));
        return R.ok();
    }
}
